﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DingVision.Infrastructure.Helpers
{
    public static class JsonHelp
    {

        public static bool JsonWrite<T>(T item,string fileName)
        {
            try
            {
                string jsonString = JsonConvert.SerializeObject(item, Formatting.Indented);
                File.WriteAllText(fileName, jsonString);
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }
        public static T JsonRead<T>(string fileName)
        {
            string jsonString = File.ReadAllText(fileName);
            T item = JsonConvert.DeserializeObject<T>(jsonString);
            return item;
        }
    }
}
